<template>
  <div>
    <TopDate></TopDate>
    <div>
      <div class="head">
        <div>
          <img :src="useraccountnumbers?.headerImg" alt="" />
        </div>
        <div>
          {{ useraccountnumbers?.username }}
        </div>
        <div>
          {{ qianming }}
        </div>
      </div>
      <div class="bianji"><img src="@/icon/bianji.png" alt="" /></div>
    </div>
    <div class="context">
      <div class="carTooncollect">
        <div>历史记录</div>
        <div>
          <div v-for="item in hisCartonn" :key="item.id">
            <img
              @click="changeManhuua(item.id)"
              :src="item.square_cover + '@150w.jpg'"
              alt=""
            />
            <span>{{ item.title }}</span>
            <span @click="removeHistorys(item.id)">删除</span>
          </div>
        </div>
      </div>
      <div class="todo">
        <div
          class="todoList"
          v-for="item in listTodo"
          :key="item.id"
          @click="changeTodo(item)"
        >
          {{ item }} <span></span>
        </div>
      </div>
    </div>
    <router-view></router-view>
    <div class="tcdl" @click="tuichuEroll">退出登录</div>
    <BottomNavigationBar></BottomNavigationBar>
  </div>
</template>
  
  <script>
import { getHistoryCartoon } from "@/api/index";
import TopDate from "@/components/TopDate.vue";
import BottomNavigationBar from "@/views/BottomNavigationBar.vue";
export default {
  components: {
    TopDate: TopDate,
    BottomNavigationBar: BottomNavigationBar,
  },
  props: {
    historyCartoon: {
      type: Array,
    },
    useraccountnumbers: {
      type: Object,
    },
  },
  data() {
    return {
      username: "张三",
      qianming: "我是张三，一日牢狱三餐",
      listTodo: [ "我在追的漫画", "设置"],
      hisCartonn: [],
    };
  },
  watch: {
    historyCartoon() {
      console.log(this.historyCartoon);
      this.getHisCartoon();
    },
  },
  methods: {
    changeTodo(i) {
      if (i == "设置") {
        this.$router.push("/user/shezhi");
      } else if (i == "我在追的漫画") {
        this.$router.push("/user/shoucang");
      }
    },
    removeHistorys(id) {
      this.$emit("remove-historys-cartoon", id);
    },
    tuichuEroll() {
      this.$emit("remove-his", 1);
      this.$router.push("/");
    },
    changeManhuua(id) {
      this.$emit("change-manhuua", id);
    },
    getHisCartoon() {
      this.hisCartonn = [];
      this.historyCartoon.forEach((el) => {
        getHistoryCartoon(el.id).then((result) => {
          this.hisCartonn.push(result.data.data);
        });
      });
    },
  },
  created() {
    //得到历史记录的数据
    this.getHisCartoon();
  },
};
</script>
  
  <style lang="less" scoped>
.tcdl {
  width: 375rem;
  text-align: center;
  height: 70rem;
  line-height: 70rem;
  color: @color1;
  font-size: 16rem;
}
.context {
  color: @color4;
  .carTooncollect {
    margin-left: 15rem;
    margin-top: 20rem;
    > div:nth-child(1) {
      font-size: 24rem;
      text-align: left;
    }
    > div:nth-child(2) {
      display: flex;
      flex-wrap: nowrap;
      width: 360rem;
      overflow: hidden;
      margin-top: 10rem;
      overflow: scroll;
      position: relative;
      text-align: left;
      img {
        margin-right: 10rem;
        height: 160rem;
        width: 155rem;
        border-radius: 10rem;
      }
      span {
        color: @color4;
        top: 10rem;
      }

      span:nth-child(2) {
        display: block;
          width: 125rem;
          height: 16rem;
        overflow: hidden !important;
        margin-top: 10rem;
      }
      span:nth-child(3) {
        color: @color1;
      }
      &::-webkit-scrollbar {
        display: none;
      }
    }
  }
  .todo {
    margin-top: 25rem;
    .todoList {
      width: 360rem;
      display: flex;
      height: 50rem;
      align-items: center;
      font-size: 16rem;
      margin-left: 15rem;
      span {
        display: flex;
        width: 5rem;
        height: 5rem;
        border-top: 2rem solid @color4;
        border-right: 2rem solid @color4;
        transform: rotate(45deg);
        position: absolute;
        right: 30rem;
      }
    }
  }
}

.head {
  width: 100vw;
  text-align: center;
  padding-top: 35rem;
  img {
    width: 160rem;
    height: 160rem;
    border-radius: 50%;
  }
  div {
    padding-top: 8rem;
  }
  div:nth-child(2) {
    font-size: 18rem;
    color: @color4;
  }
  div:nth-child(3) {
    font-size: 14rem;
    color: @color4;
  }
}
.bianji {
  width: 45rem;
  height: 45rem;
  background-color: @color1;
  border-radius: 50%;
  position: absolute;
  top: 60rem;
  right: 20rem;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: space-around;
  img {
    width: 24rem;
    height: 24rem;
  }
}
</style>